package com.orilore.gb.biz;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.orilore.gb.dao.LClassDao;
import com.orilore.gb.dao.LStudentDao;
import com.orilore.gb.entity.LClass;
import com.orilore.gb.entity.LStudent;
import com.orilore.gb.util.MySessionFactory;

public class LClassBiz {
	
	
	private  LClassDao dao;
	
	private LStudentDao  sdao;
	
	
	public List<LClass> findAllClass(){
		
		List<LClass> list = null;
		
		
		
		try {
			SqlSession session = MySessionFactory.getSession();
			
			dao = session.getMapper(LClassDao.class);
			
			
			list = dao.selectAllClass2();
			
			MySessionFactory.closeSession(session);
			
			
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		
		
		
		return list;
		
		
	}
	
	
	public void  AddClass (List<LStudent> list,LClass clazz) {
		SqlSession session = null;
		
		try {
		 session = MySessionFactory.getSession();
			
			dao = session.getMapper(LClassDao.class);
			
			sdao = session.getMapper(LStudentDao.class);
			
			
			dao.InsertClass(clazz);
			
			
			int cid = clazz.getId();
			
			
			for(LStudent  s:list) {
				
				s.setCid(cid);
				
				sdao.InsertStudent(s);
				
				
			}
			
			
			session.commit();
			
			
			
			
			
			
			
			
		}
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			
			session.rollback();
			
			
		}
		
		 
		
		
		
		
	}
	
	
	
	
	
	

}
